#ifndef HOUGH_DOOR_DETECTOR_H
#define HOUGH_DOOR_DETECTOR_H

#include "line.h"
#include "HoughSpectrum.hh"
#include <vector>

class HoughDoorDetector 
{
public: 
  struct DoorData {
    line::point_type center;
    line::point_type first;
    line::point_type second;
    double width;
    double thetaNorm;
  };
  typedef DoorData door_type;
  typedef std::vector<door_type> door_vector;

  /** Creates a door detector that uses the parameters in the given 
   * configuration file.
   */
  HoughDoorDetector(std::string configFilename);

  /** Destructor.
   */
  ~HoughDoorDetector();

  /** Returns a vector of door descriptors extracted from the given scan.
   */
  void findDoors(const line::point_vector& scan,door_vector& doors);

private:
  HoughSpectrum* hough_;
  double DOOR_HOUGH_THETA_STEP;
  double DOOR_HOUGH_RHO_STEP;
  double DOOR_HOUGH_RHO_MAX;
  double DOOR_MIN_WALL_DIST;
  double DOOR_MAX_WALL_RECESS;
  unsigned int DOOR_SIDE_WALL_NUM;
  double DOOR_WIDTH_MEAN;
  double DOOR_WIDTH_TOLL;  
  
  struct HistValue {
    unsigned int idx;
    double value;
    unsigned int hist;
    
    HistValue(unsigned int i,double v,unsigned int h) : idx(i),value(v),hist(h) { }
    bool operator<(const HistValue& hv) const { return hist < hv.hist; }
    bool operator>(const HistValue& hv) const { return hist > hv.hist; }
  };
  
  static double distance(line::point_type p1,line::point_type p2);
  
  static void computeProjection(const line::point_type& p,line::point_type& q,double theta,double rho);
};

#endif 

